package com.lam.framework.bean.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.components.dict.model.DictModel;
import com.lam.common.components.dict.model.TableDictInfo;
import com.lam.common.components.dict.service.DictService;
import com.lam.framework.bean.entity.SysDict;
import com.lam.framework.bean.mapper.DictItemMapper;
import com.lam.framework.bean.mapper.DictMapper;

/**
 * 字典配置Service业务层处理
 * 
 * @author admin
 * @date 2022-09-19
 */
@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private DictMapper dictMapper;
    @Autowired
    private DictItemMapper dictItemMapper;

    @Override
    @Transactional(readOnly = true)
	public boolean existDict(String dictCode) {
    	
    	QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dict_code", dictCode);
        queryWrapper.select("id");
		return dictMapper.exists(queryWrapper);
	}
    
    @Override
    @Transactional(readOnly = true)
	public List<DictModel> selectDictItems(String dictCode) {
		return new ArrayList<>(dictItemMapper.selectEnableItemsByCode(dictCode));
	}

	@Override
	@Transactional(readOnly = true)
	public List<DictModel> selectTableDictItems(TableDictInfo tableDictInfo) {
		return new ArrayList<>(dictItemMapper.selectTableDictItems(tableDictInfo));
	}
    
}
